package com.xc.helloworld;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.DelimiterBasedFrameDecoder;
import io.netty.handler.codec.Delimiters;
import io.netty.handler.codec.string.StringDecoder;
import io.netty.handler.codec.string.StringEncoder;

/**
 * @Package com.xc.helloworld
 * @Description 客户端过滤类
 * @Author kunshan
 * @Date 2021/1/27 6:24 下午
 */
public class NettyClientFilter extends ChannelInitializer<SocketChannel> {
//    socketChannel
//    socketChannel.pipeline().addLast("handler",new NettyServerHandler())

    @Override
    public void  initChannel(SocketChannel ch) throws Exception{
        ChannelPipeline ph = ch.pipeline();
        /*
         * 解码和编码，应和服务端一致
         * */
        ph.addLast("framer", new DelimiterBasedFrameDecoder(8192, Delimiters.lineDelimiter()));
        ph.addLast("decoder", new StringDecoder());
        ph.addLast("encoder", new StringEncoder());
        ph.addLast("handler", new HandlerClientHello()); //客户端的逻辑
    }
}
